package cn.myweixin.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;

import cn.myweixin.po.Mark;
import cn.myweixin.po.MarkKey;
import cn.myweixin.service.impl.MarkImpl;

/**
 * Servlet implementation class Ceshi
 * 可删除
 */
@WebServlet("/Ceshi")
public class Ceshi extends HttpServlet {
	private static final long serialVersionUID = 1L;
	@Autowired
	private MarkImpl    markImpl;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Ceshi() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		 Integer noticeid=(Integer) request.getAttribute("noticeid");
		 HttpSession session=request.getSession();
	//	 String openid=(String) session.getAttribute("openid");
		 String openid="1";
		MarkKey markKey=new MarkKey();
		markKey.setNoticeId( noticeid);
		markKey.setTraineeId(openid);
		List<Mark> marks = null;
		try {
			marks = markImpl.selectByTran(markKey);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String result=null;
		
		result="<table border='0'><tr><th>课程名</th><成绩></tr>";
		
		for(Mark mark:marks){
			result+="<tr><td>"+mark.getCourse().getName()+"</td><td>"+mark.getScore()+"</td></tr>";
		}
		result+="</table>";
		PrintWriter out=response.getWriter();
		out.print(result);
        out.flush();
        out.close();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
